package cool.doudou.doudada.iot.codec.auto.configuration;

import cool.doudou.doudada.iot.codec.config.IotCodecConfig;
import cool.doudou.doudada.iot.codec.core.api.BundleApi;
import cool.doudou.doudada.iot.codec.core.helper.BundleHelper;
import cool.doudou.doudada.iot.codec.properties.IotCodecProperties;
import org.osgi.framework.BundleContext;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.Import;

/**
 * IotCodecAutoConfiguration
 *
 * @author jiangcs
 * @since 2022/09/29
 */
@EnableConfigurationProperties({IotCodecProperties.class})
@Import({IotCodecConfig.class})
@AutoConfiguration
public class IotCodecAutoConfiguration {
    @DependsOn("bundleContext")
    @Bean
    public BundleHelper bundleHelper(BundleContext bundleContext, IotCodecProperties iotCodecProperties) {
        BundleApi bundleApi = new BundleApi(bundleContext);
        return new BundleHelper(bundleApi, iotCodecProperties.getBundlePath());
    }
}
